package com.punai.customer.excelparse;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ExcelListener<T> extends AnalysisEventListener<T> {

    // 解析完成后的数据集合, 监听对象初始化之后，立即初始化集合对象
    private final List<T> dataList = new ArrayList<>();

    public List<T> getDataList() {
        return dataList;
    }

    @Override
    public void invoke(T data, AnalysisContext context) {
        dataList.add(data);
    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        System.out.println("表头：" + headMap);
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        // 数据解析完成，解锁
    }


    @Override
    public void onException(Exception exception, AnalysisContext context){
        throw new RuntimeException("Excel数据异常，请检查或联系管理员！");
    }

}
